import React, { Component, PropTypes } from 'react'

import './../css/default-checkbox.css'

class CheckboxNumber extends Component {

	constructor (props, context) {
	    super(props, context)
	    const {checkboxClass, isCheck} = this.props
	    this.state = {isCheck: isCheck } // 初始化状态
	}
	componentWillReceiveProps(nextProps) {
		this.setState({isCheck: nextProps.isCheck})
	}

	handleChangeChk(e, number) {
		var isCheck = this.state.isCheck ? false : true;
		this.setState({isCheck: isCheck});
		this.props.onChange(isCheck, number);
	}

	render() {

		return (
			<input type="checkbox"
					checked={this.state.isCheck}
          number={this.props.number}
					className={this.props.checkboxClass ? this.props.checkboxClass : "default-checkbox "}
					onChange={(e) => this.handleChangeChk(e, this.props.number)}/>
		)
	}
}
CheckboxNumber.propTypes = {
	onChange: PropTypes.func.isRequired,
	isCheck : PropTypes.bool.isRequired,
  number:     PropTypes.number.isRequired
};

export default CheckboxNumber
